﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Data;

namespace KioskosJugandoLimpio.Classes
{
    public class SQL
    {
        public static DataSet fnDataSet(string query){
            DataSet ds = new DataSet();
            using (SqlConnection conn = new SqlConnection("Data Source=localhost; Initial Catalog=kioskos; Integrated Security =SSPI;"))
            {
                using(SqlDataAdapter da = new SqlDataAdapter(query , conn)){
                    da.Fill(ds);
                }
            }
            return ds;
        }
        public static DataTable fnDataTable(string query) {
            return fnDataSet(query).Tables[0];
        }

        public static object fnEscalar(string query)
        {
            return fnDataTable(query).Rows[0][0];
        }


        internal static int fnExec(string query)
        {
            int retVal;
            if (int.TryParse(fnEscalar(query + "; SELECT @@IDENTITY as A").ToString(), out retVal)) {
                return retVal;
            }
            return int.MinValue;
        }
    }
}